home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / word / wp2latex.zip / P2C.H < prev    next >
C/C++ Source or Header  |  1993-03-02  |  11KB  |  402 lines

  1. #ifndef P2C_H
  2. #define P2C_H
  3.  
  4.  
  5. /* Header file for code generated by "p2c", the Pascal-to-C translator */
  6.  
  7. /* "p2c"  Copyright (C) 1989 Dave Gillespie, version 1.18.
  8.  * This file may be copied, modified, etc. in any way.  It is not restricted
  9.  * by the licence agreement accompanying p2c itself.
  10.  */
  11.  
  12.  
  13. #include <stdio.h>
  14.  
  15.  
  16.  
  17. /* If the following heuristic fails, compile -DBSD=0 for non-BSD systems,
  18.    or -DBSD=1 for BSD systems. */
  19.  
  20. #ifdef M_XENIX
  21. # undef BSD
  22. #endif
  23.  
  24. #ifdef FILE       /* a #define in BSD, a typedef in SYSV (hp-ux, at least) */
  25. # ifndef BSD      /*  (a convenient, but horrible kludge!) */
  26. #  define BSD 1
  27. # endif
  28. #endif
  29.  
  30. #ifdef BSD
  31. # if !BSD
  32. #  undef BSD
  33. # endif
  34. #endif
  35.  
  36.  
  37. #ifdef __STDC__
  38. # include <stddef.h>
  39. # include <stdlib.h>
  40. # define HAS_STDLIB
  41. # define __CAT__(a,b)a##b
  42. #else
  43. # ifndef BSD
  44. #  include <memory.h>
  45. # endif
  46. # include <sys/types.h>
  47. # define __ID__(a)a
  48. # define __CAT__(a,b)__ID__(a)b
  49. #endif
  50.  
  51.  
  52. #ifdef BSD
  53. # include <strings.h>
  54. # define memcpy(a,b,n) (bcopy(b,a,n),a)
  55. # define memcmp(a,b,n) bcmp(a,b,n)
  56. /*
  57. # define strchr(s,c) index(s,c)
  58. # define strrchr(s,c) rindex(s,c)
  59. */
  60. #else
  61. # include <string.h>
  62. #endif
  63.  
  64. #include <ctype.h>
  65. #include <math.h>
  66. #include <setjmp.h>
  67. #include <assert.h>
  68.  
  69.  
  70. typedef struct __p2c_jmp_buf {
  71.     struct __p2c_jmp_buf *next;
  72.     jmp_buf jbuf;
  73. } __p2c_jmp_buf;
  74.  
  75.  
  76. /* Warning: The following will not work if setjmp is used simultaneously.
  77.    This also violates the ANSI restriction about using vars after longjmp,
  78.    but a typical implementation of longjmp will get it right anyway. */
  79.  
  80. #ifndef FAKE_TRY
  81. # define TRY(x)         do { __p2c_jmp_buf __try_jb;  \
  82.                  __try_jb.next = __top_jb;  \
  83.                  if (!setjmp((__top_jb = &__try_jb)->jbuf)) {
  84. # define RECOVER(x)    __top_jb = __try_jb.next; } else {
  85. # define RECOVER2(x,L)  __top_jb = __try_jb.next; } else {  \
  86.                  if (0) { L: __top_jb = __try_jb.next; }
  87. # define ENDTRY(x)      } } while (0) 
  88. #else
  89. # define TRY(x)         if (1) {
  90. # define RECOVER(x)     } else do {
  91. # define RECOVER2(x,L)  } else do { L: ;
  92. # define ENDTRY(x)      } while (0)
  93. #endif
  94.  
  95.  
  96.  
  97. #ifdef M_XENIX  /* avoid compiler bug */
  98. # define SHORT_MAX  (32767)
  99. # define SHORT_MIN  (-32768)
  100. #endif
  101.  
  102.  
  103. /* The following definitions work only on twos-complement machines */
  104. #ifndef SHORT_MAX
  105. # define SHORT_MAX  (((unsigned short) -1) >> 1)
  106. # define SHORT_MIN  (~SHORT_MAX)
  107. #endif
  108.  
  109. #ifndef INT_MAX
  110. # define INT_MAX    (((unsigned int) -1) >> 1)
  111. # define INT_MIN    (~INT_MAX)
  112. #endif
  113.  
  114. #ifndef LONG_MAX
  115. # define LONG_MAX   (((unsigned long) -1) >> 1)
  116. # define LONG_MIN   (~LONG_MAX)
  117. #endif
  118.  
  119. #ifndef SEEK_SET
  120. # define SEEK_SET   0
  121. # define SEEK_CUR   1
  122. # define SEEK_END   2
  123. #endif
  124.  
  125. #ifndef EXIT_SUCCESS
  126. # define EXIT_SUCCESS  0
  127. # define EXIT_FAILURE  1
  128. #endif
  129.  
  130.  
  131. #define SETBITS  32
  132.  
  133.  
  134. #ifdef __STDC__
  135. # define Signed     signed
  136. # define Void       void      /* Void f() = procedure */
  137. # ifndef Const
  138. #  define Const     const
  139. # endif
  140. # ifndef Volatile
  141. # define Volatile  volatile
  142. # endif
  143. # define PP(x)      x         /* function prototype */
  144. # define PV()       (void)    /* null function prototype */
  145. typedef void *Anyptr;
  146. #else
  147. # define Signed
  148. # define Void       void
  149. # ifndef Const
  150. #  define Const
  151. # endif
  152. # ifndef Volatile
  153. #  define Volatile
  154. # endif
  155. # define PP(x)      ()
  156. # define PV()       ()
  157. typedef char *Anyptr;
  158. #endif
  159.  
  160. #ifdef __GNUC__
  161. # define Inline     inline
  162. #else
  163. # define Inline
  164. #endif
  165.  
  166. #define Register    register  /* Register variables */
  167. #define Char        char      /* Characters (not bytes) */
  168.  
  169. #ifndef Static
  170. # define Static     static    /* Private global funcs and vars */
  171. #endif
  172.  
  173. #ifndef Local
  174. # define Local      static    /* Nested functions */
  175. #endif
  176.  
  177. typedef Signed   char schar;
  178. typedef unsigned char uchar;
  179. typedef unsigned char boolean;
  180.  
  181. #ifndef true
  182. # define true    1
  183. # define false   0
  184. #endif
  185.  
  186.  
  187. typedef struct {
  188.     Anyptr proc, link;
  189. } _PROCEDURE;
  190.  
  191. #ifndef _FNSIZE
  192. # define _FNSIZE  120
  193. #endif
  194.  
  195.  
  196. extern Void    PASCAL_MAIN  PP( (int, Char **) );
  197. extern Char    **P_argv;
  198. extern int     P_argc;
  199. extern short   P_escapecode;
  200. extern int     P_ioresult;
  201. extern __p2c_jmp_buf *__top_jb;
  202.  
  203.  
  204. #ifdef P2C_H_PROTO   /* if you have Ansi C but non-prototyped header files */
  205. extern Char    *strcat      PP( (Char *, Const Char *) );
  206. extern Char    *strchr      PP( (Const Char *, int) );
  207. extern int      strcmp      PP( (Const Char *, Const Char *) );
  208. extern Char    *strcpy      PP( (Char *, Const Char *) );
  209. extern size_t   strlen      PP( (Const Char *) );
  210. extern Char    *strncat     PP( (Char *, Const Char *, size_t) );
  211. extern int      strncmp     PP( (Const Char *, Const Char *, size_t) );
  212. extern Char    *strncpy     PP( (Char *, Const Char *, size_t) );
  213. extern Char    *strrchr     PP( (Const Char *, int) );
  214.  
  215. extern Anyptr   memchr      PP( (Const Anyptr, int, size_t) );
  216. extern Anyptr   memmove     PP( (Anyptr, Const Anyptr, size_t) );
  217. extern Anyptr   memset      PP( (Anyptr, int, size_t) );
  218. #ifndef memcpy
  219. extern Anyptr   memcpy      PP( (Anyptr, Const Anyptr, size_t) );
  220. extern int      memcmp      PP( (Const Anyptr, Const Anyptr, size_t) );
  221. #endif
  222.  
  223. extern int      atoi        PP( (Const Char *) );
  224. extern double   atof        PP( (Const Char *) );
  225. extern long     atol        PP( (Const Char *) );
  226. extern double   strtod      PP( (Const Char *, Char **) );
  227. extern long     strtol      PP( (Const Char *, Char **, int) );
  228. #endif /*P2C_H_PROTO*/
  229.  
  230. #ifndef HAS_STDLIB
  231. extern Anyptr   malloc      PP( (size_t) );
  232. extern Void     free        PP( (Anyptr) );
  233. #endif
  234.  
  235. extern int      _OutMem     PV();
  236. extern int      _CaseCheck  PV();
  237. extern int      _NilCheck   PV();
  238. extern int    _Escape     PP( (int) );
  239. extern int    _EscIO      PP( (int) );
  240.  
  241. extern long     ipow        PP( (long, long) );
  242. extern Char    *strsub      PP( (Char *, Char *, int, int) );
  243. extern Char    *strltrim    PP( (Char *) );
  244. extern Char    *strrtrim    PP( (Char *) );
  245. extern Char    *strrpt      PP( (Char *, Char *, int) );
  246. extern Char    *strpad      PP( (Char *, Char *, int, int) );
  247. extern int      strpos2     PP( (Char *, Char *, int) );
  248. extern long     memavail    PV();
  249. extern int      P_peek      PP( (FILE *) );
  250. extern int      P_eof       PP( (FILE *) );
  251. extern int      P_eoln      PP( (FILE *) );
  252. extern Void     P_readpaoc  PP( (FILE *, Char *, int) );
  253. extern Void     P_readlnpaoc PP( (FILE *, Char *, int) );
  254. extern long     P_maxpos    PP( (FILE *) );
  255. extern Char    *P_trimname  PP( (Char *, int) );
  256. extern long    *P_setunion  PP( (long *, long *, long *) );
  257. extern long    *P_setint    PP( (long *, long *, long *) );
  258. extern long    *P_setdiff   PP( (long *, long *, long *) );
  259. extern long    *P_setxor    PP( (long *, long *, long *) );
  260. extern int      P_inset     PP( (unsigned, long *) );
  261. extern int      P_setequal  PP( (long *, long *) );
  262. extern int      P_subset    PP( (long *, long *) );
  263. extern long    *P_addset    PP( (long *, unsigned) );
  264. extern long    *P_addsetr   PP( (long *, unsigned, unsigned) );
  265. extern long    *P_remset    PP( (long *, unsigned) );
  266. extern long    *P_setcpy    PP( (long *, long *) );
  267. extern long    *P_expset    PP( (long *, long) );
  268. extern long     P_packset   PP( (long *) );
  269. extern int      P_getcmdline PP( (int l, int h, Char *line) );
  270. extern Void     TimeStamp   PP( (int *Day, int *Month, int *Year,
  271.                  int *Hour, int *Min, int *Sec) );
  272. extern Void    P_sun_argv  PP( (char *, int, int) );
  273.  
  274.  
  275. /* I/O error handling */
  276. #define _CHKIO(cond,ior,val,def)  ((cond) ? P_ioresult=0,(val)  \
  277.                       : P_ioresult=(ior),(def))
  278. #define _SETIO(cond,ior)          (P_ioresult = (cond) ? 0 : (ior))
  279.  
  280. /* Following defines are suitable for the HP Pascal operating system */
  281. #define FileNotFound     10
  282. #define FileNotOpen      13
  283. #define FileWriteError   38
  284. #define BadInputFormat   14
  285. #define EndOfFile        30
  286.  
  287. /* Creating temporary files */
  288. #if (defined(BSD) || defined(NO_TMPFILE)) && !defined(HAVE_TMPFILE)
  289. # define tmpfile()  (fopen(tmpnam(NULL), "w+"))
  290. #endif
  291.  
  292. /* File buffers */
  293. #define FILEBUF(f,sc,type) sc int __CAT__(f,_BFLAGS);   \
  294.                sc type __CAT__(f,_BUFFER)
  295.  
  296. #define RESETBUF(f,type)   (__CAT__(f,_BFLAGS) = 1)
  297. #define SETUPBUF(f,type)   (__CAT__(f,_BFLAGS) = 0)
  298.  
  299. #define GETFBUF(f,type)    (*((__CAT__(f,_BFLAGS) == 1 &&   \
  300.                    ((__CAT__(f,_BFLAGS) = 2),   \
  301.                 fread(&__CAT__(f,_BUFFER),  \
  302.                       sizeof(type),1,(f)))),\
  303.                   &__CAT__(f,_BUFFER)))
  304. #define AGETFBUF(f,type)   ((__CAT__(f,_BFLAGS) == 1 &&   \
  305.                  ((__CAT__(f,_BFLAGS) = 2),   \
  306.                   fread(&__CAT__(f,_BUFFER),  \
  307.                     sizeof(type),1,(f)))),\
  308.                 __CAT__(f,_BUFFER))
  309.  
  310. #define PUTFBUF(f,type,v)  (GETFBUF(f,type) = (v))
  311. #define CPUTFBUF(f,v)      (PUTFBUF(f,char,v))
  312. #define APUTFBUF(f,type,v) (memcpy(GETFBUF(f,type), (v),  \
  313.                    sizeof(__CAT__(f,_BUFFER))))
  314.  
  315. #define GET(f,type)        (__CAT__(f,_BFLAGS) == 1 ?   \
  316.                 fread(&__CAT__(f,_BUFFER),sizeof(type),1,(f)) :  \
  317.                 (__CAT__(f,_BFLAGS) = 1))
  318.  
  319. #define PUT(f,type)        (fwrite(&__CAT__(f,_BUFFER),sizeof(type),1,(f)),  \
  320.                 (__CAT__(f,_BFLAGS) = 0))
  321. #define CPUT(f)            (PUT(f,char))
  322.  
  323. #define BUFEOF(f)       (__CAT__(f,_BFLAGS) != 2 && P_eof(f))
  324. #define BUFFPOS(f)       (ftell(f) - (__CAT__(f,_BFLAGS) == 2))
  325.  
  326. typedef struct {
  327.     FILE *f;
  328.     FILEBUF(f,,Char);
  329.     Char name[_FNSIZE];
  330. } _TEXT;
  331.  
  332. /* Memory allocation */
  333. #ifdef __GCC__
  334. # define Malloc(n)  (malloc(n) ?: (Anyptr)_OutMem())
  335. #else
  336. extern Anyptr __MallocTemp__;
  337. # define Malloc(n)  ((__MallocTemp__ = malloc(n)) ? __MallocTemp__ : (Anyptr)_OutMem())
  338. #endif
  339. #define FreeR(p)    (free((Anyptr)(p)))    /* used if arg is an rvalue */
  340. #define Free(p)     (free((Anyptr)(p)), (p)=NULL)
  341.  
  342. /* sign extension */
  343. #define SEXT(x,n)   ((x) | -(((x) & (1L<<((n)-1))) << 1))
  344.  
  345. /* packed arrays */   /* BEWARE: these are untested! */
  346. #define P_getbits_UB(a,i,n,L)   ((int)((a)[(i)>>(L)-(n)] >>   \
  347.                        (((~(i))&((1<<(L)-(n))-1)) << (n)) &  \
  348.                        (1<<(1<<(n)))-1))
  349.  
  350. #define P_getbits_SB(a,i,n,L)   ((int)((a)[(i)>>(L)-(n)] <<   \
  351.                        (16 - ((((~(i))&((1<<(L)-(n))-1))+1) <<\
  352.                           (n)) >> (16-(1<<(n))))))
  353.  
  354. #define P_putbits_UB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |=   \
  355.                  (x) << (((~(i))&((1<<(L)-(n))-1)) << (n)))
  356.  
  357. #define P_putbits_SB(a,i,x,n,L) ((a)[(i)>>(L)-(n)] |=   \
  358.                  ((x) & (1<<(1<<(n)))-1) <<   \
  359.                  (((~(i))&((1<<(L)-(n))-1)) << (n)))
  360.  
  361. #define P_clrbits_B(a,i,n,L)    ((a)[(i)>>(L)-(n)] &=   \
  362.                  ~( ((1<<(1<<(n)))-1) <<   \
  363.                    (((~(i))&((1<<(L)-(n))-1)) << (n))) )
  364.  
  365. /* small packed arrays */
  366. #define P_getbits_US(v,i,n)     ((int)((v) >> ((i)<<(n)) & (1<<(1<<(n)))-1))
  367. #define P_getbits_SS(v,i,n)     ((int)((long)(v) << (SETBITS - (((i)+1) << (n))) >> (SETBITS-(1<<(n)))))
  368. #define P_putbits_US(v,i,x,n)   ((v) |= (x) << ((i) << (n)))
  369. #define P_putbits_SS(v,i,x,n)   ((v) |= ((x) & (1<<(1<<(n)))-1) << ((i)<<(n)))
  370. #define P_clrbits_S(v,i,n)      ((v) &= ~( ((1<<(1<<(n)))-1) << ((i)<<(n)) ))
  371.  
  372. #define P_max(a,b)   ((a) > (b) ? (a) : (b))
  373. #define P_min(a,b)   ((a) < (b) ? (a) : (b))
  374.  
  375.  
  376. /* Fix toupper/tolower on Suns and other stupid BSD systems */
  377. #ifdef toupper
  378. # undef toupper
  379. # undef tolower
  380. # define toupper(c)   my_toupper(c)
  381. # define tolower(c)   my_tolower(c)
  382. #endif
  383.  
  384. #ifndef _toupper
  385. # if 'A' == 65 && 'a' == 97
  386. #  define _toupper(c)  ((c)-'a'+'A')
  387. #  define _tolower(c)  ((c)-'A'+'a')
  388. # else
  389. #  define _toupper(c)  toupper(c)
  390. #  define _tolower(c)  tolower(c)
  391. # endif
  392. #endif
  393.  
  394.  
  395. #endif    /* P2C_H */
  396.  
  397.  
  398.  
  399. /* End. */
  400.  
  401.  
  402.